package com.tiger.admin.interceptor;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {
    @Value("${Whites}")
    private String Whites;

    @Value("${WhitesSplitSymbol}")
    private String WhitesSplitSymbol;

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(authInterceptor);
        registration.addPathPatterns("/**");
        if(Whites != null && !Whites.isEmpty()) {
            registration.excludePathPatterns(Arrays.asList(Whites.split(WhitesSplitSymbol)));
        }
    }
}
